<template>
  <div>
    <el-dialog
      title="流程查看"
      :visible="visible"
      width="60%"
      @close="visible = false"
      :close-on-click-modal="false"
    >
      <workflowEditPanel
        ref="workflowEditPanel"
        :nodeData="nodeData"
      ></workflowEditPanel>

      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="confirm" size="small"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import workflowEditPanel from "@/components/Workflow/panelView";

export default {
  components: { workflowEditPanel },
  props: {},
  watch: {
    value: {
      handler() {
        //this.load();
      },
      deep: true,
    },
    visible(newVal, oldVal) {
      if (!newVal && oldVal) this.hide();
    },
  },
  model: {
    prop: "value",
    event: "change",
  },
  data() {
    return {
      loading: false,
      visible: false,
      defaultLabelWidth: "150px",

      nodeData: {},
      data: {},
    };
  },
  methods: {
    confirm() {
      this.commit();
    },
    show(value) {
      // {version:'',id:''}
      this.visible = true;
      this.loadData(value.version, value.id);
    },
    hide() {
      this.visible = false;
      this.value = {};
      this.control = {};
    },
    loadData(value) {},
    commit() {
      this.hide();
    },
    loadData(versionid, id) {
      let _this = this;
      this.$store
        .dispatch("workflow/getWorkflowVersion", { versionid, id })
        .then((res) => {
          _this.nodeData =
            res.drawingInfo.length == 0
              ? this.defaultNode()
              : JSON.parse(res.drawingInfo);
          _this.data = res;
          if (_this.nodeData.nodeList)
            _this.nodeData.nodeList.forEach((n) => (n.viewOnly = true));
          _this.$refs.workflowEditPanel.loadNodeData();
        });
    },
    defaultNode() {
      return {
        name: "",
        nodeList: [],
        lineList: [],
      };
    },
  },
};
</script>

<style></style>
